#include "stdafx.h"
#include "shadow_follow.h"
#include "clientinterfaces.h"
#include <iltclient.h>
#include "ltclientshell.h"
#include "Screen/tex_mgr.h"


void shadow_follow::set_trans()
{
	if (!m_car)
	{
		return;
	}

	 LTVector _pos;
	 LTRotation _rot;
	 g_pLTClient->GetObjectPos(m_car,&_pos);
	 g_pLTClient->GetObjectRotation(m_car,&_rot);
	 _pos.y+=0.05;

	LTVector temp_pos;
	temp_pos=_pos+_rot.Forward()*m_length-_rot.Right()*m_width;
	m_poly.verts[0].x=temp_pos.x;
	m_poly.verts[0].y=temp_pos.y;
	m_poly.verts[0].z=temp_pos.z;


	temp_pos=_pos+_rot.Forward()*m_length+_rot.Right()*m_width;
	m_poly.verts[1].x=temp_pos.x;
	m_poly.verts[1].y=temp_pos.y;
	m_poly.verts[1].z=temp_pos.z;


	temp_pos=_pos-_rot.Forward()*m_length+_rot.Right()*m_width;
	m_poly.verts[2].x=temp_pos.x;
	m_poly.verts[2].y=temp_pos.y;
	m_poly.verts[2].z=temp_pos.z;


	temp_pos=_pos-_rot.Forward()*m_length-_rot.Right()*m_width;
	m_poly.verts[3].x=temp_pos.x;
	m_poly.verts[3].y=temp_pos.y;
	m_poly.verts[3].z=temp_pos.z;







}

void shadow_follow::render()
{
	if (!m_car)
	{
		m_car=g_pLTClient->GetClientObject();
	}
	if (!m_tex)
	{
		m_tex=tex_mgr::single().get_tex("shadow");
	}
	if (m_tex)
	{
		
	}

	set_trans();

	g_pLTCDrawPrim->SetTransformType(DRAWPRIM_TRANSFORM_WORLD);
	g_pLTCDrawPrim->SetZBufferMode(DRAWPRIM_ZRW);
	g_pLTCDrawPrim->SetColorOp(DRAWPRIM_MODULATE);
	g_pLTCDrawPrim->SetTexture(m_tex);
	g_pLTCDrawPrim->DrawPrim(&m_poly);
	

}

shadow_follow::shadow_follow():
m_car(0),
m_tex(0)
{
	for (int i=0;i<4;++i)
	{
		m_poly.verts[i].rgba.a=180;
		m_poly.verts[i].rgba.r=50;
		m_poly.verts[i].rgba.g=50;
		m_poly.verts[i].rgba.b=50;
	}
	m_poly.verts[0].u=0.26f;
	m_poly.verts[0].v=0.0f;

	m_poly.verts[1].u=0.73f;
	m_poly.verts[1].v=0.0f;

	m_poly.verts[2].u=0.73f;
	m_poly.verts[2].v=1.0f;

	m_poly.verts[3].u=0.26f;
	m_poly.verts[3].v=1.0f;





}

shadow_follow::~shadow_follow()
{

}

void shadow_follow::set_obj( HOBJECT _obj )
{
	m_car=_obj;

}